package com.example.hangzhou.welbeing.mytestdemoapp.activity;

import android.animation.Animator;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.transition.ArcMotion;
import android.transition.ChangeBounds;
import android.transition.Transition;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.hangzhou.welbeing.mytestdemoapp.R;
import com.example.hangzhou.welbeing.mytestdemoapp.animation.animationActivity.AnimatedSpreadOneActivity;

/**
 * 杭州惟君医疗科技有限公司11
 * Created by 20433 on 2018/3/2
 */

public class coordinateLayoutOneActivity extends AppCompatActivity {

    private ImageView imageview;
    private FloatingActionButton fb_01;
    private FloatingActionButton fb;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coordinate_layout_one);
        fb = (FloatingActionButton) findViewById(R.id.fab_01);
        fb_01 = (FloatingActionButton) findViewById(R.id.fab);
        imageview = (ImageView) findViewById(R.id.imageview);
        fb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view,"sdghbubfdgb",Snackbar.LENGTH_SHORT).setAction("撤销",new View.OnClickListener(){
                    @Override
                    public void onClick(View view){
                        Toast.makeText(coordinateLayoutOneActivity.this, "撤销了删除", Toast.LENGTH_SHORT).show();
                    }
                }).show();
            }
        });
        fb_01.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_01 = new Intent(coordinateLayoutOneActivity.this, AnimatedSpreadOneActivity.class);
               // startActivity(intent_01, ActivityOptions.makeSceneTransitionAnimation(coordinateLayoutOneActivity.this, fb, "shareNames").toBundle());
                startActivity(intent_01, ActivityOptions.makeClipRevealAnimation(fb,0,0,fb.getRight(),fb.getBottom()).toBundle());
            }
        });
        setUpWindowTransition();
    }

    private void setUpWindowTransition() {

        //进入的动画监听
        final ChangeBounds ts = new ChangeBounds();
        ts.setPathMotion(new ArcMotion());
        ts.addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionStart(Transition transition) {


            }

            @Override
            public void onTransitionEnd(Transition transition) {
                ts.removeListener(this);
                animateRevealShow(imageview);
            }

            @Override
            public void onTransitionCancel(Transition transition) {

            }

            @Override
            public void onTransitionPause(Transition transition) {

            }

            @Override
            public void onTransitionResume(Transition transition) {

            }
        });
        getWindow().setSharedElementEnterTransition(ts);

    }

    private void animateRevealShow(ImageView imageview) {

        int cx = imageview.getWidth() / 2;
        int cy = imageview.getHeight() / 2;
        int finalRadius = Math.max(imageview.getWidth(), imageview.getHeight());
        Animator anim = ViewAnimationUtils.createCircularReveal(imageview, cx, cy, finalRadius /5, finalRadius);
        imageview.setVisibility(View.VISIBLE);
        anim.setDuration(500);
        anim.start();
        //开始前设置标题的背景
       // imageview.setImageResource(R.color.bg_title_bar);

        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                //设置一个显示的动画
                imageview.animate().alpha(1).setStartDelay(100).start();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    }
}
